package controller;

import java.sql.SQLException;
import java.util.ArrayList;

import parsers.CategoriaParser;

import com.j256.ormlite.dao.Dao;

import dtos.CategoriaDTO;
import model.Categoria;
import DB.DatabaseHelper;
import android.content.Context;

public class CategoriaController {
	private static CategoriaController instance = null;
	protected CategoriaController() {
	}
	public static CategoriaController getInstance() {
		if(instance == null) {
    	  instance = new CategoriaController();
		}
		return instance;
	}
	public void index(){
		
	}
	public void add(){
		
	}
	public void update(){
			
		}
	public void delete(){
		
	}
	public ArrayList<CategoriaDTO> obtenerCategorias(Context context) {
		try {
			DatabaseHelper db=new DatabaseHelper(context);
			Dao<Categoria, Integer> catDao = db.getCategoriaDao();
			ArrayList<Categoria> categorias= (ArrayList<Categoria>) catDao.queryForAll();
			return CategoriaParser.getInstance().fromModelToDTOArrayEager(categorias);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
}
